<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="/common-app/taglibs.jsp"%>
<%@ taglib uri="/WEB-INF/iristaglib.tld" prefix="iris"%>
<!DOCTYPE html>
<html>
<head>
<title>项目审核</title>
<%@ include file="/common/meta.jsp"%>

<script type="text/javascript" src="${res}/js/opinion/opinion.js"></script>
<script type="text/javascript" src="${res}/js/validate/irisvalidator.js"></script>
<script type="text/javascript">
var prcWin = new progressWin("${res}");//初始化遮罩层
messageTip.check_nopass="提示信息";
function processsFun(type){
	    //获取申报书查看页面的附件清单
	    var passFiles = "";
	    var isExtsis = false;
	    
	    try{
	    	if("${param.subGrantCode}"!="0" ){
		     passFiles =  document.getElementById("prpFrame").contentWindow.setAttachMessage("prpContent_upload");
	    	}
		     //isExtsis =  document.getElementById("prpFrame").contentWindow.isExistAttach();//判断申报书是否有附件
	    }catch(ex){
	    	//拿不到符合的附件清单号
	    	//isExtsis=false;
	    }
	    
		$("#passFiles").attr("value",passFiles);
        
		var opn = $("#opinionContent").val();
		if(opn==null||opn==""){
			opn = $("#opinionContent").text();
		}
		if($.trim(opn).length==0){
			scmWarn("请输入审核意见!");
			return false;
		}
		if(opn.length>500){
			scmWarn("审核意见限500字内!");
			return false;
		}
		if(type=="approveQhh" && roleId=='8'){
			//成果处审核输入名称和结果校验,名称为非必填
			var v_result=$("#recomend_org_value").val();
			var jianding_date=$("#jianding_date").val();
/* 			alert("v_name="+v_name+"  v_result="+v_result);
 */			if(v_result==''){
					alert("鉴定结果不能为空");
				return false;
			}
			if(jianding_date==''){
					alert("鉴定批准日期不能为空");
				return false;
			}else{
				var _reTimeReg =/^\d{4}[-]\d{2}[-]\d{2}$/;
				if(!_reTimeReg.test(jianding_date)){
					alert("鉴定批准日期格式为yyyy-mm-dd");
					return false;
				}
			}
		}
		
		/*
		if(isExtsis){
		 if("${param.roleId}"=="8"){
			if(passFiles==""&&type=='return'){
				if(!window.confirm("确定没有一个附件符合条件吗？")){
				   return false;
			    }
			}
		 }
		}
		*/
		if(type=="return"){
			if(!window.confirm("确定退回该项目吗？")){
				   return false;
			}
		}
		
		if(type=="notpass"){
			if(!window.confirm("确定不同意申报吗？如果确定，该鉴定证书将作废。")){
				   return false;
			}
		}
		
		if(type=="notpass2"){
			type="notpass";
			if(!window.confirm("确定不同意吗？如果确定，该鉴定证书将作废。")){
				   return false;
			}
		}
		
		var prpCode = encodeURIComponent("${param.prpCodes}");
		var options = {
				type:'post',
				data:{
					"prpCodes":"${param.prpCodes}",
					"type":"${param.type}",
					"status":"${param.status}",
					"category":"${userOpinion.category}",
					"opinion":opn,
					"passFiles":passFiles,
					"cgmc":$("#cgmc").val(),
					"reviewResult":$("#recomend_org_value").val(),
					"jianding_date":$("#jianding_date").val()
				},
				beforeSend : function() {
					$("input[type='button'][id!='back']").attr("disabled",true);
					$("#type").attr("value",type);
					//$("#passFiles").attr("value",passFiles);
					//prcWin.openWin();//打开遮罩层
					
				}, // 表单提交前的回调函数
				success : function(msg) {
						if(msg.indexOf(":")!=-1){
							var obj = eval("(" + msg + ")");
							if(obj.checkList!=null){
								var list = obj.checkList ;
								for ( var i = 0; i < list.length; i++) {
									irisValaddMsg(list[i]);
								}
								prcWin.closeWin();
								irisValShowMsg($("#wbox1"));
								$("input[type='button'][id!='back']").attr("disabled",false);
								return ;
							} 
						}
					if(msg.indexOf('操作成功')!=-1 || msg=='success')
						scmSuccess(msg);
					else{
						prcWin.closeWin();
						irisValaddMsg(msg);
						irisValShowMsg($("#wbox1"));
						$("input[type='button'][id!='back']").attr("disabled",false);
						return ;
					}
					prcWin.closeWin();
					if("${param.subGrantCode}"=="0" ){
						parent.$("#searchBt").click();
						parent.irisGrid.getGridDom().jqGrid("refresh",0);//0是本页1是首页	
						parent.tb_remove();
					}
					if("${param.subGrantCode}"!="0" ){
						parent.currefresh=false;
						window.parent.opener.search();
						window.parent.opener.reflushBu();
						window.setTimeout("window.close()", 2000);	
					}
					
					
					$("input[type='button'][id!='back']").attr("disabled",false);
				
				},// 表单成功提交后的回调函数
				error : function() {
					scmError("操作失败,请联系系统管理员");
					$("input[type='button'][id!='back']").attr("disabled",false);
					//prcWin.closeWin();
				},
				url: "${ctx}/prpapprove/"+type
			};
		$.ajax(options);
	//$("#mainForm").ajaxSubmit(options);
	//	parent.irisGrid.getGridDom().jqGrid("refresh",0);//0是本页1是首页
}
var roleId="";
$(document).ready(function(){

	//如果是成果处，则显示填写名称和结果
	roleId="${userRoleId}";
	if(roleId=='8'){
		$("#cgjd_table").show();
	}	
	
$("#back").click(function(){
	if("${param.subGrantCode}"=="0" ){
	parent.irisGrid.getGridDom().jqGrid("refresh",0);//0是本页1是首页
	parent.$("#searchBt").click();
	parent.tb_remove();
	}
	if("${param.subGrantCode}"!="0" ){
	window.close();
	}
});
refreshOpinins();

});



function openprpapprovedialog(flag){
	if (flag) {
		var url="${ctx}/prpapprove/openprpapprovedialog?category=${userOpinion.category}&flag="+flag+"&showGrant=true&TB_iframe=true&height=390&width=720";
		var title="";
		tb_show(title,url,false);
	}
}

function viewComment(){
	
	var url="${ctx}/proposal/view/audit-comment-view?posCode="+encodeURIComponent("${param.posCode}")+"&flag=historyOpinion&TB_iframe=true&height=390&width=720";
    var title="历史审核意见";
    tb_show(title,url,false);
}


function setChangeValue(selObj){
	if (selObj.value > 0)
		$("#opinionContent").val($(selObj).find("option:selected").attr("title"));
	else 
		$("#opinionContent").val("");
}
//刷新意见下拉列表
function refreshOpinins(){
	$.ajax({
		async:true,
		type:'post',
		data:{
			"userOpinion.grantCode":"${param.grantCode}",
			"userOpinion.category":"${userOpinion.category}",
			"flag":"ajaxOpinions"
		},
		success : function(data) {
			$("#opininsSpan").html("");
				var opinins='<select onchange="setChangeValue(this)" style="width:150px; overflow:hidden">'+
								'<option value="-1">请选择</option>';
				for (var i in data) {
					   if(data[i].content.length > 20){
					       opinins+='<option title = "'+data[i].content+'" value="'+data[i].id+'">'+data[i].content.substr(0,20)+"......"+'</option>';
					   }else{
						   opinins+='<option title = "'+data[i].content+'" value="'+data[i].id+'">'+data[i].content+'</option>';
					   }
				}
					opinins+='</select>';
				$("#opininsSpan").html(opinins);
		
		},
		error : function() {
			scmError("操作失败,请联系系统管理员");
		},
		url: "${ctx}/prpapprove/openprpapprovedialog_cgjdzs"
	});
}

function initControlValue(objId){
	var name="";
	var obj=$("#"+objId);
    if(obj.is("select")){
    	name=obj.attr("name");
    	obj.parent().children("input[name$='"+name+"_value'][type='hidden']").val($("#"+objId).find("option:selected").val());
    	$("#"+objId).parent().children("input[name$='"+name+"_name']").val($("#"+objId).find("option:selected").text());
    }
   
    else if(obj.is(":radio")){
    	name=obj.attr("name");
    	if(obj.is(":checked")){//如果被选中
    		//alert($("#"+objId).val());		
    		obj.parents("table").find("input[name$='"+name+"_value'][type='hidden']").val($("#"+objId).val());
    	}
    	else{
    		
    		obj.parents("table").find("input[name$='"+name+"_value'][type='hidden']").val("");
    	}
    }else if(obj.is(":checkbox")){
    	name=obj.attr("name");
    	if(obj.is(":checked"))//如果被选中
    		obj.parent().find("input[name$='"+name+"_value'][type='hidden']").val($("#"+objId).val());
    	else
    		obj.parent().find("input[name$='"+name+"_value'][type='hidden']").val("");
    }else{
    	name=obj.attr("id");
    	obj.parents("td").find("input[name$='"+name+"_name'][type='hidden']").val(obj.val());
    	obj.parents("td").find("input[name$='"+name+"_code'][type='hidden']").val($("#"+objId+"_hideId").val());
    }  	
}


</script>
</head>
<body>
<c:if test="${param.subGrantCode ne '0' or empty param.subGrantCode}">
    <center>

        <iframe id="prpFrame"  frameborder="0"   height="500px" width="1000px" src=""></iframe>

	</center>
 </c:if>    
    
    
	<!-- <form method="post" id="mainForm"> -->
		<input type="hidden" id="prpCodes" name="prpCodes" value="${param.prpCodes}" />
		<input type="hidden" id="type" name="type" value="${param.type}" />
		<input type="hidden" id="category" value="${userOpinion.category}"/>
		
		<input type="hidden" id="passFiles" name="passFiles" value="" />
		
		<table id="cgjd_table" class="t_css" width="100%"  border="0" cellpadding="0" cellspacing="1" style="margin-left: 0;margin-right: 0;margin-top: 0;display: none;">
		    <tr style="margin-left: 0;margin-right: 0;margin-top: 0;">
		    <col width="20%"/>
		    <col width="15%"/>
		    <col width="15%"/>
		    <col width="15%"/>
		    <col width="15%"/>
		    <col width="20%"/>
		    <td align="right">成果名称：</td>
		    <td>
		    	<input id="cgmc" name="cgmc" label="成果名称" type="text" class="input_css required"  maxlength="100" value="${zhTitle }"/> 
		    </td>
		    <td align="right"><span class="color_red">*</span>鉴定结果：</td>
		    <td >
					<cpt:select id="recomend_org"  key="cgjdResult222"  value="" style="width:80px;" onChange="initControlValue(this.id);"></cpt:select>
					<input type="hidden" id="recomend_org_value" name="recomend_org_value" class="required" value="" label="鉴定结果">
			</td>
			<td align="right"><span class="color_red">*</span>鉴定批准日期：</td>
		    <td >
				<cpt:date id="jianding_date" name="jianding_date" value="${sercverSysDate1}" className=" required date  " size="10" label="鉴定批准日期" ></cpt:date> 
			</td>
		    </tr>
	   </table>
		
		<center>
			选择常用审核意见：
			<span id="opininsSpan">
				<%-- <select onchange="setChangeValue(this)">
					<option value="-1">请选择</option>
					<s:iterator value="#request.opinions" var="o">
						<s:if test="#o != null">
							<option value="${o.id }">${o.content }</option>
						</s:if>
					</s:iterator>
				</select> --%>
			</span>
			<div>
			    <button onclick="javascript:viewComment()" class="button_01">查看历史审核意见</button>
				<button onclick="saveUserOpinion('${ctx}', this, 'main-opinion')" class="button_01">添加至常用意见箱</button>
				<button onclick="openprpapprovedialog('list4opinions')" class="button_01">编辑常用意见箱</button>
			</div>
			 <table class="t_css" width="970px"  border="0" cellpadding="0" cellspacing="1" style="margin-left: 0;margin-right: 0;margin-top: 0;">
			    <tr style="margin-left: 0;margin-right: 0;margin-top: 0;">
			    <td style="color: red;margin-left: 0;margin-right: 0;margin-top: 0;" align="left">${opinion }</td>
			    </tr>
		        <tr class="li_1">
		          <td width="100%"><textarea name="opinionContent" id="opinionContent" style="width:100%;resize:none;" class="input_textarea" rows="8" maxlength="500" onfocus="InitInput.setMaxLength(this,500)"></textarea></td>
		        </tr>
	      	</table>
	      	<br/>
      	</center>
      	<br/>
      <div style="text-align: center;">
      <!--业务科室科长-->
     
     <c:if test="${param.subGrantCode ne '0' or empty param.subGrantCode}">
     <security:authorize ifAnyGranted="A_PROPOSAL_AD_PASS_2">
        &nbsp;<input type="button" class="button_01" value="同意" id="approveQhh" processType="approveQhh" onclick="processsFun('approveQhh')"/>
     </security:authorize>
     </c:if>
      <c:if test="${param.subGrantCode eq '0' }">
     <security:authorize ifAnyGranted="A_PROPOSAL_AD_PASS_2">
        &nbsp;<input type="button" class="button_01" value="同意" id="approveQhh" processType="approveQhh" onclick="processsFun('approveMove')"/>
     </security:authorize>
     </c:if>
     <!--归口管理部门-->
     <security:authorize ifAnyGranted="A_AUTH_TJBM">
        &nbsp;<input type="button" class="button_01" value="同意" id="approveQhh" processType="approveQhh" onclick="processsFun('approveQhh')"/>
     </security:authorize>
     
      <!--业务科室科员-->
      <security:authorize ifAnyGranted="A_PROPOSAL_AD_PASS_1">
      	&nbsp;<input type="button" class="button_01" value="同意" id="approveQhh" processType="approveQhh" onclick="processsFun('approveQhh')"/>
      </security:authorize>	
      
      <!--申报单位管理员-->
       <security:authorize ifAnyGranted="A_PROPOSAL_AD_SUBMIT">
      	&nbsp;<input type="button" class="button_01" value="同意" id="approveQhh" processType="approveQhh" onclick="processsFun('approveQhh')"/>
       </security:authorize>
      
        <security:authorize ifAnyGranted="A_PROPOSAL_AD_PASS_2">
      	&nbsp;<input type="button" class="button_01" value="不同意" id="veto" processType="notpass" onclick="processsFun('notpass2')"/>
     </security:authorize> 
      
      	 &nbsp;<input type="button" class="button_01" value="退回修改" id="return" processType="return" onclick="processsFun('return')"/>
      	 
<%--         
     <security:authorize ifAnyGranted="A_AUTH_TJBM">
      	&nbsp;<input type="button" class="button_01" value="不同意申报" id="veto" processType="notpass" onclick="processsFun('notpass')"/>
     </security:authorize>  --%>
      
     
     
        &nbsp;<input type="button" class="button_01" value="关闭" id="back"/>
		</div>
	<!-- </form> -->
	
	<script type="text/javascript">
	function loadPrpView(){
		  document.getElementById("prpFrame").src = "${ctx}/proposal/view-prp?posCodeStr="+encodeURIComponent("${param.posCode}")+"&grantCodeStr=<iris:des3 code="${param.grantCode}|${curDate}" encryptKey="111111222222333333444444" />&subGrantCodeStr=<iris:des3 code="${param.subGrantCode}|${curDate}" encryptKey="111111222222333333444444" />";
	}
	
	if("${param.subGrantCode}"!="0" ){
	loadPrpView();
	}
	</script>
</body>
</html>